package com.ryhx.main;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;

import com.ryhx.util.ConfigUtil;
import com.ryhx.util.ConnectionUtil;
import com.ryhx.util.MysqlUtil;
/**
 * entity 和 mapper 文件生成器
 * @author yaojinshan
 * @since 2017-08-02 17:03
 */
public class EntityAndMapperFileProducer {
	static StringBuilder mapperContentSB = null;//mapper文件生成sb
	static StringBuilder entityContentSB = null;//entity文件生成sb
	static String INDENTATION_1 = "    ";// 缩进1个单位 即4个空格
	static String INDENTATION_2 = "        ";// 缩进2个单位 即8个空格
	static String INDENTATION_3 = "            ";// 缩进3个单位 即12个空格
	static String INDENTATION_4 = "                ";// 缩进4个单位 即16个空格
	static String NEWLINESTR = "\n";//一个换行标识
	//mapper.xml头部
	public static String mapperXmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ NEWLINESTR + "<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">" + NEWLINESTR + NEWLINESTR;
	//mapper.xml注释
	public static String mapperXmlComment = "<!-- 这里可以写Mapper文件的注释  " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) +" -->" + NEWLINESTR;
	public static String primaryKeyColumnName = null;//主键列名
	public static String primaryKeyInEntityName = null;//主键列名在实体中的名称
	public static String[] columnArray = null;// 列名数组
	public static String[] entityPropertyNameArray = null;//实体类的属性名称数组
	public static String[] columnDefaultValueArray = null;//列默认值数组
	public static String[] columnTypeArray = null;//列类型数组
	public static String[] entityPropertyTypeArray = null;//实体类的属性类型数组
	public static int[] columnDatasizeArray = null;//列的大小数组
	public static int[] columnDigitsArray = null;//列的精度数组
	public static int[] columnNullableArray = null;//列是否为空 数组  0 不能为空 1 可以为空
	public static String[] columnAutoIncrementArray = null;//列是否自增 数组  是否自增 YES自增 NO非自增
	public static String[] columnRemarksArray = null;//列的注释 数组
	
	public static void main(String[] args) {
		try {
			createEntityAndMapperFile();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 创建 Entity和Mapper文件
	 * @throws Exception 
	 */
 	public static void createEntityAndMapperFile() throws Exception{
		Connection connection = ConnectionUtil.getConnection();
		try {
			//获取数据库元属性
			DatabaseMetaData dbMeta = connection.getMetaData();
			//获取数据库名称
			String database_name = connection.getCatalog();
			//获取表的主键名称
			primaryKeyColumnName = getPrimaryKeyColumnName(dbMeta,database_name);
			primaryKeyInEntityName = getColumnInEntityName(primaryKeyColumnName);
			//ResultSet tableResultSet = null;
			//多表查询 第一个参数为数据库名称  第二个参数  可以模糊匹配表名  第三个参数可以是具体的表名 第四个参数 固定格式 new String[]{"TABLE"} 查询类型是表的 应该也可以查视图 触发器等类型 
			//tableResultSet = dbMeta.getTables(database_name,null,null,new String[]{"TABLE"});  
			//单表查询
			//tableResultSet = dbMeta.getTables(database_name,null,ConfigUtil.database_table,new String[]{"TABLE"});  
			//String tableName = "";//表名
			//while(tableResultSet.next()){  
				//tableName = tableResultSet.getString("TABLE_NAME");  
				//System.out.println(tableName);
			//}
			//提取表内的字段的名字和类型 
			ResultSet colRet = dbMeta.getColumns(null,null, ConfigUtil.database_table,"%");
			//获取列的其他属性
			ResultSetMetaData rsMeta = getResultSetMetaData(connection);
			//初始化静态数据：将数据库表字段属性 全部初始化到静态变量里边
			initStaticData(colRet,rsMeta);
			 //创建mapper文件
			createMapperFile();
			//创建实体类文件
			createEntityFile();
			ConnectionUtil.releaseConn();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
 	/**
 	 * 创建Mapper文件
 	 * @param connection
 	 * @throws Exception
 	 */
 	public static void createMapperFile() throws Exception{
 		mapperContentSB = new StringBuilder();
		mapperContentSB.append(mapperXmlHeader);//添加Mapper头部
		mapperContentSB.append(mapperXmlComment);//Mapper注释
		//添加 mapper行数据
		addNamespaceRowContent();
		//添加createTable的sql
		addCreateTableSql();
		//添加 列名集合 sql语句
		addSelectSql();
		//添加 where 条件sql语句
		addWhereSql();
		//添加 排序 分组 分页 sql语句
		addOrderGroupLimitSql();
		//添加get单个对象sql语句
		addGetObjectSql();
		//添加get列表对象sql语句
		addGetObjectListSql();
		//添加get列表对象数量sql语句
		addGetObjectListCountSql();

		//添加 getObjectListByParamsSql语句
		addGetObjectListByParamsSql();
		//添加 getObjectListCountByParamsSql 语句
		addGetObjectListCountByParamsSql();
		
		//添加insert一个对象sql语句
		addInsertObjectSql();
		//添加update对象sql语句
		addUpdateObjectSql();
		//添加update对象 WithoutNull sql语句
		addUpdateObjectWithoutNullSql();
		//添加update对象 ByWhereSql sql语句
		addUpdateObjecByWhereSqlSql();
		//添加 delete对象sql语句
		addDeleteObjectSql();
		//添加 delete对象list sql语句
		addDeleteObjectListSql();
		//添加 delete对象list byWhere sql语句
		addDeleteObjectListByWhereSql();
		//添加 batch insert对象 sql语句
		addBatchInsertObjectSql();
		//添加 batch update对象 sql语句
		addBatchUpdateObjectSql();
		//添加 batch delete对象 sql语句
		addBatchDeleteObjectSql();
		//添加 batch delete对象 list sql语句
		addBatchDeleteObjectListSql();
		//添加mapper结束标签
		mapperContentSB.append("</mapper>");
		//将mapper内容 写入mapper文件
		writeMapperContentToMapperFile();
 	}
 	/**
 	 * 创建实体类文件
 	 */
 	public static void createEntityFile(){
 		entityContentSB = new StringBuilder();
 		//添加package
 		entityContentSB.append("package " + ConfigUtil.modelPackagePath + ";" + NEWLINESTR + NEWLINESTR);
 		//添加import
 		HashSet<String> hset = new HashSet<>();
 		for(int i = 0 ; i < entityPropertyTypeArray.length; i++ ){
 			if(entityPropertyTypeArray[i].indexOf("java.lang") >=0){
 				continue;
 			}else{
 				hset.add(entityPropertyTypeArray[i]);
 			}
 		}
 		Iterator<String> it = hset.iterator();
 		while(it.hasNext()){
 			entityContentSB.append("import " + it.next() + ";" + NEWLINESTR);
 		}
 		
 		//添加序列化支持
 		entityContentSB.append("import java.io.Serializable;");
 		
 		entityContentSB.append(NEWLINESTR);
 		entityContentSB.append(NEWLINESTR);
 		
 		//添加类注释  --- 省略

 		//添加类声明
 		entityContentSB.append("public class " + ConfigUtil.simpleModelName +" implements Serializable {" + NEWLINESTR);
 		entityContentSB.append(NEWLINESTR);

 		//添加默认的序列化Id
 		entityContentSB.append(INDENTATION_1 + "private static final long serialVersionUID = 1L;" + NEWLINESTR);
 		//添加类属性声明
 		for(int i = 0 ; i < entityPropertyNameArray.length; i ++){
 			entityContentSB.append(INDENTATION_1 + "private " + entityPropertyTypeArray[i].substring(entityPropertyTypeArray[i].lastIndexOf(".") + 1) + " "+ entityPropertyNameArray[i] + ";" + "//" + columnRemarksArray[i] + NEWLINESTR);
 		}
 		entityContentSB.append(NEWLINESTR);
 		
 		//添加属性的get set 方法
 		// 属性的类型  属性首字母大写
 		String attr_type,attrFirstCharToUpper,attr_name;
 		for(int i = 0 ; i < entityPropertyNameArray.length; i ++){
 			attr_name = entityPropertyNameArray[i];
 			attr_type = entityPropertyTypeArray[i].substring(entityPropertyTypeArray[i].lastIndexOf(".") + 1);
 			attrFirstCharToUpper =attr_name.substring(0, 1).toUpperCase() + attr_name.substring(1);
 			//添加get方法
 			entityContentSB.append(INDENTATION_1 + "public " + attr_type  + " get" + attrFirstCharToUpper + "() {" +  NEWLINESTR);
 			entityContentSB.append(INDENTATION_2 + "return " + attr_name  + ";" +  NEWLINESTR);
 			entityContentSB.append(INDENTATION_1 + "}" +  NEWLINESTR);
 			entityContentSB.append(NEWLINESTR);
 			//添加set方法
 			entityContentSB.append(INDENTATION_1 + "public void set" + attrFirstCharToUpper + "("+attr_type + " " + attr_name +") {" +  NEWLINESTR);
 			entityContentSB.append(INDENTATION_2 + "this." + attr_name  + " = " + attr_name +";" +  NEWLINESTR);
 			entityContentSB.append(INDENTATION_1 + "}" +  NEWLINESTR);
 			entityContentSB.append(NEWLINESTR);
 		}
 		
 		//添加java文件结束
 		entityContentSB.append("}");
 		writeEntityContentToEntityFile();
 	}
 	/**
 	 * 初始化静态数据：将数据库表字段属性 全部初始化到静态变量里边
 	 * @param colRet 列一部分属性集合
 	 * @param rsMeta 列另一部分属性集合
 	 * @throws Exception 
 	 */
 	private static void initStaticData(ResultSet colRet, ResultSetMetaData rsMeta) throws Exception {
 		int columnCount = rsMeta.getColumnCount();
 		columnArray = new String[columnCount];// 列名数组
		entityPropertyNameArray = new String[columnCount];//实体类的属性名称数组
		columnDefaultValueArray = new String[columnCount];//实体类名称默认值数组
		columnTypeArray = new String[columnCount];//列类型数组
		entityPropertyTypeArray = new String[columnCount];//实体类的属性类型数组
		columnDatasizeArray = new int[columnCount];//列的大小数组
		columnDigitsArray = new int[columnCount];//列的精度数组
		columnNullableArray =  new int[columnCount];//列是否为空 数组  0 不能为空 1 可以为空
		columnAutoIncrementArray = new String[columnCount];//列是否自增 数组  是否自增 YES自增 NO非自增
		columnRemarksArray = new String[columnCount];//列的注释 数组
		for (int i = 1; i <= columnCount; i++) {
			// 对应数据类型的类
			String columnClassName = rsMeta.getColumnClassName(i);
			//日期类型需要手动转换一下
			if("java.sql.Timestamp".equals(columnClassName)){
				entityPropertyTypeArray[i - 1] = "java.util.Date";
				continue;
			}
			//System.out.println("获得列" + i + "对应数据类型的类:" + columnClassName);
			entityPropertyTypeArray[i - 1] = columnClassName;
		}
		String columnName,columnType,autoIncrement,remarks,columnDefault; 
		int datasize,digits,nullable;
		int arrayIndex = 0;
		while(colRet.next()) { 
			// 列属性的顺序为 ： 列名 -- 列类型(列大小,列精度) -- 是否为空 -- 是否自增 -- 注释 -- 默认值
			columnName = colRet.getString("COLUMN_NAME"); //列名称 
			columnType = colRet.getString("TYPE_NAME"); // 数据库列类型名称
			datasize = colRet.getInt("COLUMN_SIZE"); //列的大小
			digits = colRet.getInt("DECIMAL_DIGITS"); //小数部分的位数即数据精度
			nullable = colRet.getInt("NULLABLE"); // 是否为空 0 不能为空 1 可以为空
			autoIncrement = colRet.getString("IS_AUTOINCREMENT"); // 是否自增 YES自增 NO非自增
			remarks = colRet.getString("REMARKS"); //列的注释
			columnDefault = colRet.getString("COLUMN_DEF"); // 获取列的默认值
			columnArray[arrayIndex] = columnName.toLowerCase();
			entityPropertyNameArray[arrayIndex] = getColumnInEntityName(columnName);
			columnDefaultValueArray[arrayIndex] = MysqlUtil.getColumnInsertDefaultStr(columnType, columnDefault);
			columnTypeArray[arrayIndex] = columnType;
			columnDatasizeArray[arrayIndex] = datasize;
			columnDigitsArray[arrayIndex] = digits;
			columnNullableArray[arrayIndex] = nullable;
			columnAutoIncrementArray[arrayIndex] = autoIncrement;
			columnRemarksArray[arrayIndex] = remarks;
			arrayIndex++;
		}
	}
	/**
 	 * 获取 resultSetMetaData 为了表的列数量 以及表的各个列的属性  以及 列属性对应的entity实体属性
 	 * @param connection
 	 * @return
 	 * @throws Exception
 	 */
	private static ResultSetMetaData getResultSetMetaData(Connection connection) throws Exception {
		String sql = "select * from " + ConfigUtil.database_table + " limit 0,10";
		PreparedStatement stmt;
		stmt = connection.prepareStatement(sql);
		ResultSet rs = stmt.executeQuery(sql);
		return rs.getMetaData();
	}
	/**
	 * 添加createTable的sql
	 * @throws Exception 
	 */
	public static void addCreateTableSql() throws Exception {
		StringBuilder  createSqlSB = new StringBuilder();//创建表sql语句
		//遵循固定格式插入
		createSqlSB.append(INDENTATION_1 + "<sql id=\"createTable\">" + NEWLINESTR).append(INDENTATION_2  + "DROP TABLE `"+ ConfigUtil.database_table +"`;" + NEWLINESTR);
		createSqlSB.append(INDENTATION_2 + "CREATE TABLE `"+ ConfigUtil.database_table +"`(" + NEWLINESTR);
		if(null != primaryKeyColumnName){
			createSqlSB.append(INDENTATION_3 + "PRIMARY KEY (`"+primaryKeyColumnName +"`) ," + NEWLINESTR);
		}
		for(int i = 0;i < columnArray.length; i++ ){
			createSqlSB.append(INDENTATION_3 + "`" + columnArray[i]+ "` " + MysqlUtil.getColumnTypeStr(columnTypeArray[i],columnDatasizeArray[i],columnDigitsArray[i]));
			createSqlSB.append(MysqlUtil.getNullableStr(columnNullableArray[i]));
			createSqlSB.append(MysqlUtil.getAutoIncrement(columnAutoIncrementArray[i]));
			createSqlSB.append(MysqlUtil.getColumnRemarks(columnRemarksArray[i]));
			createSqlSB.append(MysqlUtil.getColumnDefaultStr(columnTypeArray[i],columnDefaultValueArray[i]));
			if(i ==  columnArray.length - 1){
				createSqlSB.append(NEWLINESTR);
			}else{
				createSqlSB.append("," + NEWLINESTR);
			}
		}
		createSqlSB.append(INDENTATION_2 + ")" + NEWLINESTR);
		createSqlSB.append(INDENTATION_1 + "</sql>" + NEWLINESTR);
		mapperContentSB.append(createSqlSB.toString());
	}
	/**
	 * 添加 列名集合 sql语句
	 * @throws Exception 
	 */
	public static void addSelectSql() throws Exception {
		StringBuilder  selectSqlSB = new StringBuilder();//列名集合 sql语句
		selectSqlSB.append(INDENTATION_1 +  "<sql id=\"selectSql" + ConfigUtil.simpleModelName + "\">" + NEWLINESTR);
		for(int i = 0 ; i < columnArray.length; i ++){
			if(i == columnArray.length -1){
				selectSqlSB.append(INDENTATION_2 + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + " "  + entityPropertyNameArray[i] + NEWLINESTR);
			}else{
				selectSqlSB.append(INDENTATION_2 + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + " "  + entityPropertyNameArray[i] +  "," + NEWLINESTR);
			}
		}
		selectSqlSB.append(INDENTATION_1 + "</sql>" + NEWLINESTR);
		mapperContentSB.append(selectSqlSB.toString());
	}
	/**
	 * 添加 where 条件sql
	 */
	public static void addWhereSql() throws Exception {
		StringBuilder  whereSqlSB = new StringBuilder();
		whereSqlSB.append(INDENTATION_1 +  "<sql id=\"whereSql" + ConfigUtil.simpleModelName + "\">" + NEWLINESTR);
		for(int i = 0 ; i < columnArray.length; i ++){
			whereSqlSB.append(INDENTATION_2 + "<if test=\"" + entityPropertyNameArray[i] + "!=null\"> and " + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + " = #{" + entityPropertyNameArray[i] + "}</if>" + NEWLINESTR);
		}
		whereSqlSB.append(INDENTATION_2 + "<if test=\"whereSql!=null\"> ${whereSql}</if>" + NEWLINESTR);
		whereSqlSB.append(INDENTATION_1 + "</sql>" + NEWLINESTR);
		mapperContentSB.append(whereSqlSB.toString());
	}
	/**
	 * 添加 排序 分组 分页 sql语句
	 */
	public static void addOrderGroupLimitSql() {
		StringBuilder  orderGroupLimitSqlSB = new StringBuilder();//排序分组分页 sql语句
		orderGroupLimitSqlSB.append(INDENTATION_1 + "<sql id=\"orderGroupLimit\">" + NEWLINESTR);
		orderGroupLimitSqlSB.append(INDENTATION_2 + "<if test=\"groupBy != null and groupBy != ''\"> group by  ${groupBy} </if>" + NEWLINESTR);
		orderGroupLimitSqlSB.append(INDENTATION_2 + "<if test=\"orderBy != null and orderBy != ''\"> order by  ${orderBy} </if>" + NEWLINESTR);
		orderGroupLimitSqlSB.append(INDENTATION_2 + "<if test=\"limit != null\"> LIMIT <if test=\"limitIndex != null\">#{limitIndex},</if>#{limit} </if>" + NEWLINESTR);
		orderGroupLimitSqlSB.append(INDENTATION_1 + "</sql>" + NEWLINESTR);
		mapperContentSB.append(orderGroupLimitSqlSB.toString());
	}
	/**
	 * 添加get单个对象sql语句
	 */
	public static void addGetObjectSql() {
		StringBuilder  getObjectSqlSB = new StringBuilder();
		getObjectSqlSB.append(INDENTATION_1 + "<select id=\"get" + ConfigUtil.simpleModelName + "\" parameterType=\"hashmap\" resultType=\"" + ConfigUtil.simpleModelName + "\">" + NEWLINESTR);
		getObjectSqlSB.append(INDENTATION_2 +  "select <include refid=\"selectSql" + ConfigUtil.simpleModelName + "\"/> from " + ConfigUtil.database_table +" " + ConfigUtil.firstCharLowerSimpleModelName + " where 1=1 <include refid=\"whereSql" + ConfigUtil.simpleModelName + "\"/> <include refid=\"orderGroupLimit\"/>" + NEWLINESTR);
		getObjectSqlSB.append(INDENTATION_1 + "</select>" + NEWLINESTR);
		mapperContentSB.append(getObjectSqlSB.toString());
	}
	/**
	 * 添加get列表对象sql语句
	 */
	public static void addGetObjectListSql() {
		StringBuilder  getObjectListSqlSB = new StringBuilder();
		getObjectListSqlSB.append(INDENTATION_1 + "<select id=\"get" + ConfigUtil.simpleModelName + "List\" parameterType=\"" + ConfigUtil.simpleModelName + "\" resultType=\"" + ConfigUtil.simpleModelName + "\">" + NEWLINESTR);
		getObjectListSqlSB.append(INDENTATION_2 +  "select <include refid=\"selectSql" + ConfigUtil.simpleModelName + "\"/> from " + ConfigUtil.database_table +" " + ConfigUtil.firstCharLowerSimpleModelName + " where 1=1 <include refid=\"whereSql" + ConfigUtil.simpleModelName + "\"/> <include refid=\"orderGroupLimit\"/>" + NEWLINESTR);
		getObjectListSqlSB.append(INDENTATION_1 + "</select>" + NEWLINESTR);
		mapperContentSB.append(getObjectListSqlSB.toString());
	}
	/**
	 * 添加get列表对象数量sql语句
	 */
	public static void addGetObjectListCountSql() {
		StringBuilder  getObjectListCountSqlSB = new StringBuilder();
		getObjectListCountSqlSB.append(INDENTATION_1 + "<select id=\"get" + ConfigUtil.simpleModelName + "ListCount\" parameterType=\"" + ConfigUtil.simpleModelName + "\" resultType=\"int\">" + NEWLINESTR);
		getObjectListCountSqlSB.append(INDENTATION_2 +  "select count(1) from " + ConfigUtil.database_table +" " + ConfigUtil.firstCharLowerSimpleModelName + " where 1=1 <include refid=\"whereSql" + ConfigUtil.simpleModelName + "\"/> " + "<if test=\"groupBy != null\"> group by  ${groupBy} </if>" + NEWLINESTR);
		getObjectListCountSqlSB.append(INDENTATION_1 + "</select>" + NEWLINESTR);
		mapperContentSB.append(getObjectListCountSqlSB.toString());
	}
	/**
	 * 添加 getObjectListByParamsSql语句
	 */
	public static void addGetObjectListByParamsSql() {
		StringBuilder  getObjectListByParamsSqlSB = new StringBuilder();
		getObjectListByParamsSqlSB.append(INDENTATION_1 + "<select id=\"get" + ConfigUtil.simpleModelName + "ListByParams\" parameterType=\"hashmap\" resultType=\"" + ConfigUtil.simpleModelName + "\">" + NEWLINESTR);
		getObjectListByParamsSqlSB.append(INDENTATION_2 +  "select <include refid=\"selectSql" + ConfigUtil.simpleModelName + "\"/> from " + ConfigUtil.database_table +" " + ConfigUtil.firstCharLowerSimpleModelName + " where 1=1 <include refid=\"whereSql" + ConfigUtil.simpleModelName + "\"/> <include refid=\"orderGroupLimit\"/>" + NEWLINESTR);
		getObjectListByParamsSqlSB.append(INDENTATION_1 + "</select>" + NEWLINESTR);
		mapperContentSB.append(getObjectListByParamsSqlSB.toString());
	}
	/**
	 * 添加 getObjectListCountByParamsSql语句
	 */
	public static void addGetObjectListCountByParamsSql() {
		StringBuilder  getObjectListCountByParamsSqlSB = new StringBuilder();
		getObjectListCountByParamsSqlSB.append(INDENTATION_1 + "<select id=\"get" + ConfigUtil.simpleModelName + "ListCountByParams\" parameterType=\"hashmap\" resultType=\"int\">" + NEWLINESTR);
		getObjectListCountByParamsSqlSB.append(INDENTATION_2 +  "select count(1) from " + ConfigUtil.database_table +" " + ConfigUtil.firstCharLowerSimpleModelName + " where 1=1 <include refid=\"whereSql" + ConfigUtil.simpleModelName + "\"/> " + "<if test=\"groupBy != null\"> group by  ${groupBy} </if>" + NEWLINESTR);
		getObjectListCountByParamsSqlSB.append(INDENTATION_1 + "</select>" + NEWLINESTR);
		mapperContentSB.append(getObjectListCountByParamsSqlSB.toString());
	}
	/**
	 * 添加insert一个对象sql语句
	 */
	public static void addInsertObjectSql() {
		StringBuilder  insertSqlSB = new StringBuilder();//插入sql语句
		insertSqlSB.append(INDENTATION_1 + "<insert id=\"insert" + ConfigUtil.simpleModelName + "\" parameterType=\"" + ConfigUtil.simpleModelName + "\">" + NEWLINESTR);
		insertSqlSB.append(INDENTATION_2 + "<selectKey resultType=\"Long\" order=\"AFTER\" keyProperty=\"" + primaryKeyInEntityName + "\">" + NEWLINESTR);
		insertSqlSB.append(INDENTATION_3 + "<choose><when test=\"" + primaryKeyInEntityName + "==null\">SELECT LAST_INSERT_ID() AS " + primaryKeyInEntityName + "</when><otherwise>SELECT #{" + primaryKeyInEntityName + "} as " + primaryKeyInEntityName + "</otherwise></choose>" + NEWLINESTR);
		insertSqlSB.append(INDENTATION_2 + "</selectKey>" + NEWLINESTR);
		insertSqlSB.append(INDENTATION_2 + "insert into "+ ConfigUtil.database_table + " (" + NEWLINESTR);
		for(int i = 0 ; i < columnArray.length;i++){
			if(columnArray[i].equals(primaryKeyColumnName)){
				insertSqlSB.append(INDENTATION_3 + "<if test=\""+ primaryKeyInEntityName + "!=null\">`" + primaryKeyColumnName + "`,</if>"+ NEWLINESTR + INDENTATION_3);
			}else if(i > 0 && i < columnArray.length - 1){
				insertSqlSB.append("`"+columnArray[i]+"`,");
			}else if(i == columnArray.length - 1){
				insertSqlSB.append("`"+columnArray[i]+"`)" + NEWLINESTR);
			}
		}
		insertSqlSB.append(INDENTATION_2 + "values(" + NEWLINESTR);
		for(int i = 0 ; i < columnArray.length;i++){
			if(columnArray[i].equals(primaryKeyColumnName)){
				insertSqlSB.append(INDENTATION_3 + "<if test=\""+ primaryKeyInEntityName + "!=null\">#{" + primaryKeyInEntityName + "},</if>"+ NEWLINESTR);
			}else if(i > 0 && i < columnArray.length - 1){
				if(MysqlUtil.TYPE_NAME_DATETIME.equals(columnTypeArray[i].toLowerCase()) || MysqlUtil.TYPE_NAME_DATE.equals(columnTypeArray[i].toLowerCase())){
					insertSqlSB.append(INDENTATION_3 +"<choose><when test=\"" + entityPropertyNameArray[i] + "==null\">" + columnDefaultValueArray[i] + "</when><otherwise>#{" + entityPropertyNameArray[i] + ",jdbcType=TIMESTAMP}</otherwise></choose>," + NEWLINESTR);
				}else{
					insertSqlSB.append(INDENTATION_3 +"<choose><when test=\"" + entityPropertyNameArray[i] + "==null\">" + columnDefaultValueArray[i] + "</when><otherwise>#{" + entityPropertyNameArray[i] + "}</otherwise></choose>," + NEWLINESTR);
				}
			}else if(i == columnArray.length - 1){
				insertSqlSB.append(INDENTATION_3 +"<choose><when test=\"" + entityPropertyNameArray[i] + "==null\">" + columnDefaultValueArray[i] + "</when><otherwise>#{" + entityPropertyNameArray[i] + "}</otherwise></choose>" + NEWLINESTR);
			}
		}
		insertSqlSB.append(INDENTATION_2 + ")" + NEWLINESTR);
		insertSqlSB.append(INDENTATION_1 + "</insert>" + NEWLINESTR);
		mapperContentSB.append(insertSqlSB.toString());
	}
	/**
	 * 添加update对象sql语句
	 */
	public static void addUpdateObjectSql(){
		StringBuilder  updateSqlSB = new StringBuilder();
		updateSqlSB.append(INDENTATION_1 + "<update id=\"update" + ConfigUtil.simpleModelName + "\" parameterType=\"" + ConfigUtil.simpleModelName + "\">" + NEWLINESTR);
		updateSqlSB.append(INDENTATION_2 + "update "+ ConfigUtil.database_table +" "+ ConfigUtil.firstCharLowerSimpleModelName +" set " + NEWLINESTR);
		for(int i = 1 ; i < columnArray.length;i++){
			if(MysqlUtil.TYPE_NAME_DATETIME.equals(columnTypeArray[i].toLowerCase()) || MysqlUtil.TYPE_NAME_DATE.equals(columnTypeArray[i].toLowerCase())){
				updateSqlSB.append(INDENTATION_3 +"<choose><when test=\"" + entityPropertyNameArray[i] + "!=null\">" + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + "=#{" + entityPropertyNameArray[i] + ",jdbcType=TIMESTAMP},</when><otherwise>" + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + "=" + columnDefaultValueArray[i] + ",</otherwise></choose>" + NEWLINESTR);
			}else{
				updateSqlSB.append(INDENTATION_3 +"<choose><when test=\"" + entityPropertyNameArray[i] + "!=null\">" + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + "=#{" + entityPropertyNameArray[i] + "},</when><otherwise>" + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + "=" + columnDefaultValueArray[i] + ",</otherwise></choose>" + NEWLINESTR);
			}
		}
		updateSqlSB.append(INDENTATION_3 + ConfigUtil.firstCharLowerSimpleModelName + "." + primaryKeyColumnName + " = " + primaryKeyColumnName + " " + NEWLINESTR);
		updateSqlSB.append(INDENTATION_2 + "where " + ConfigUtil.firstCharLowerSimpleModelName + "." + primaryKeyColumnName + "=#{" + primaryKeyInEntityName + "}" + NEWLINESTR);
		updateSqlSB.append(INDENTATION_1 + "</update>" + NEWLINESTR);
		mapperContentSB.append(updateSqlSB.toString());
	}
	/**
	 * 添加update对象 WithoutNull sql语句
	 */
	public static void addUpdateObjectWithoutNullSql(){
		StringBuilder  updateObjectWithoutNullSql = new StringBuilder();
		updateObjectWithoutNullSql.append(INDENTATION_1 + "<update id=\"update" + ConfigUtil.simpleModelName + "WithoutNull\" parameterType=\"" + ConfigUtil.simpleModelName + "\">" + NEWLINESTR);
		updateObjectWithoutNullSql.append(INDENTATION_2 + "update "+ ConfigUtil.database_table +" "+ ConfigUtil.firstCharLowerSimpleModelName +" set " + NEWLINESTR);
		for(int i = 1 ; i < columnArray.length;i++){
			if(MysqlUtil.TYPE_NAME_DATETIME.equals(columnTypeArray[i].toLowerCase()) || MysqlUtil.TYPE_NAME_DATE.equals(columnTypeArray[i].toLowerCase())){
				updateObjectWithoutNullSql.append(INDENTATION_3 +"<choose><when test=\"" + entityPropertyNameArray[i] + "!=null\">" + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + "=#{" + entityPropertyNameArray[i] + ",jdbcType=TIMESTAMP},</when></choose>" + NEWLINESTR);
			}else{
				updateObjectWithoutNullSql.append(INDENTATION_3 +"<choose><when test=\"" + entityPropertyNameArray[i] + "!=null\">" + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + "=#{" + entityPropertyNameArray[i] + "},</when></choose>" + NEWLINESTR);
			}
		}
		updateObjectWithoutNullSql.append(INDENTATION_3 + ConfigUtil.firstCharLowerSimpleModelName + "." + primaryKeyColumnName + " = " + primaryKeyColumnName + " " + NEWLINESTR);
		updateObjectWithoutNullSql.append(INDENTATION_2 + "where " + ConfigUtil.firstCharLowerSimpleModelName + "." + primaryKeyColumnName + "=#{" + primaryKeyInEntityName + "}" + NEWLINESTR);
		updateObjectWithoutNullSql.append(INDENTATION_1 + "</update>" + NEWLINESTR);
		mapperContentSB.append(updateObjectWithoutNullSql.toString());
	}
	/**
	 * 添加update对象 ByWhereSql sql语句
	 */
	public static void addUpdateObjecByWhereSqlSql(){
		StringBuilder  updateObjectByWhereSqlSB = new StringBuilder();
		updateObjectByWhereSqlSB.append(INDENTATION_1 + "<update id=\"update" + ConfigUtil.simpleModelName + "ByWhereSql\" parameterType=\"hashmap\">" + NEWLINESTR);
		updateObjectByWhereSqlSB.append(INDENTATION_2 + "update "+ ConfigUtil.database_table +" "+ ConfigUtil.firstCharLowerSimpleModelName +" set " + NEWLINESTR);
		for(int i = 1 ; i < columnArray.length;i++){
			if(MysqlUtil.TYPE_NAME_DATETIME.equals(columnTypeArray[i].toLowerCase()) || MysqlUtil.TYPE_NAME_DATE.equals(columnTypeArray[i].toLowerCase())){
				updateObjectByWhereSqlSB.append(INDENTATION_3 +"<choose><when test=\"" + entityPropertyNameArray[i] + "!=null\">" + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + "=#{" + entityPropertyNameArray[i] + ",jdbcType=TIMESTAMP},</when></choose>" + NEWLINESTR);
			}else{
				updateObjectByWhereSqlSB.append(INDENTATION_3 +"<choose><when test=\"" + entityPropertyNameArray[i] + "!=null\">" + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + "=#{" + entityPropertyNameArray[i] + "},</when></choose>" + NEWLINESTR);
			}
		}
		updateObjectByWhereSqlSB.append(INDENTATION_3 + ConfigUtil.firstCharLowerSimpleModelName + "." + primaryKeyColumnName + " = " + primaryKeyColumnName + " " + NEWLINESTR);
		updateObjectByWhereSqlSB.append(INDENTATION_2 + "where ${whereSql}" + NEWLINESTR);
		updateObjectByWhereSqlSB.append(INDENTATION_1 + "</update>" + NEWLINESTR);
		mapperContentSB.append(updateObjectByWhereSqlSB.toString());
	}
	/**
	 * 添加 delete对象sql语句
	 */
	public static void addDeleteObjectSql(){
		StringBuilder  deleteObjectSql = new StringBuilder();
		deleteObjectSql.append(INDENTATION_1 + "<delete id=\"delete" + ConfigUtil.simpleModelName + "\" parameterType=\"hashmap\">" + NEWLINESTR);
		deleteObjectSql.append(INDENTATION_2 + "delete "+ ConfigUtil.firstCharLowerSimpleModelName +" from " + ConfigUtil.database_table + " " + ConfigUtil.firstCharLowerSimpleModelName + " where 1=1 " + NEWLINESTR);
		deleteObjectSql.append(INDENTATION_3 + "and " + ConfigUtil.firstCharLowerSimpleModelName + "." + primaryKeyColumnName + " = #{" + primaryKeyInEntityName + "}" + NEWLINESTR);
		deleteObjectSql.append(INDENTATION_1 + "</delete>" + NEWLINESTR);
		mapperContentSB.append(deleteObjectSql.toString());
	}
	/**
	 * 添加 delete对象list sql语句
	 */
	public static void addDeleteObjectListSql(){
		StringBuilder  deleteObjectListSql = new StringBuilder();
		deleteObjectListSql.append(INDENTATION_1 + "<delete id=\"delete" + ConfigUtil.simpleModelName + "List\" parameterType=\"hashmap\">" + NEWLINESTR);
		deleteObjectListSql.append(INDENTATION_2 + "delete "+ ConfigUtil.firstCharLowerSimpleModelName +" from " + ConfigUtil.database_table + " " + ConfigUtil.firstCharLowerSimpleModelName + " where 1=1 " + NEWLINESTR);
		deleteObjectListSql.append(INDENTATION_2 + "<include refid=\"whereSql" + ConfigUtil.simpleModelName + "\"/>" + NEWLINESTR);
		deleteObjectListSql.append(INDENTATION_1 + "</delete>" + NEWLINESTR);
		mapperContentSB.append(deleteObjectListSql.toString());
	}
	/**
	 * 添加 delete对象list byWhere sql语句
	 */
	public static void addDeleteObjectListByWhereSql(){
		StringBuilder  deleteObjectListByWhereSqlSB = new StringBuilder();
		deleteObjectListByWhereSqlSB.append(INDENTATION_1 + "<delete id=\"delete" + ConfigUtil.simpleModelName + "ByWhereSql\" parameterType=\"hashmap\">" + NEWLINESTR);
		deleteObjectListByWhereSqlSB.append(INDENTATION_2 + "delete "+ ConfigUtil.firstCharLowerSimpleModelName +" from " + ConfigUtil.database_table + " " + ConfigUtil.firstCharLowerSimpleModelName + " where ${whereSql} " + NEWLINESTR);
		deleteObjectListByWhereSqlSB.append(INDENTATION_1 + "</delete>" + NEWLINESTR);
		mapperContentSB.append(deleteObjectListByWhereSqlSB.toString());
	}
	/**
	 * 添加 batch insert对象 sql语句
	 */
	public static void addBatchInsertObjectSql(){
		StringBuilder  batchInsertObjectSqlSB = new StringBuilder();
		batchInsertObjectSqlSB.append(INDENTATION_1 + "<insert id=\"batchInsert" + ConfigUtil.simpleModelName + "\" parameterType=\"java.util.List\">" + NEWLINESTR);
		batchInsertObjectSqlSB.append(INDENTATION_2 + "insert into " + ConfigUtil.database_table + " ( " + NEWLINESTR);
		for(int i = 1 ; i < columnArray.length ; i ++){
			if(i == columnArray.length - 1){
				batchInsertObjectSqlSB.append(INDENTATION_3 + "`"+ columnArray[i] +"`)" + NEWLINESTR);
				continue;
			}
			batchInsertObjectSqlSB.append(INDENTATION_3 + "`"+ columnArray[i] +"`," + NEWLINESTR);
		}
		batchInsertObjectSqlSB.append(INDENTATION_2 + "values" + NEWLINESTR);
		batchInsertObjectSqlSB.append(INDENTATION_2 + "<foreach collection=\"list\" item= \"item\" index =\"index\" separator=\",\">" + NEWLINESTR);
		batchInsertObjectSqlSB.append(INDENTATION_3 + "(" + NEWLINESTR);
		for(int i = 1 ; i < columnArray.length ; i ++){
			if(i == columnArray.length - 1){
				if(MysqlUtil.TYPE_NAME_DATETIME.equals(columnTypeArray[i].toLowerCase()) || MysqlUtil.TYPE_NAME_DATE.equals(columnTypeArray[i].toLowerCase())){
					batchInsertObjectSqlSB.append(INDENTATION_4+"<choose><when test=\"item." + entityPropertyNameArray[i] + "!=null\">" + "#{item." + entityPropertyNameArray[i] + ",jdbcType=TIMESTAMP}</when><otherwise>" + columnDefaultValueArray[i] + "</otherwise></choose>" + NEWLINESTR);
				}else{
					batchInsertObjectSqlSB.append(INDENTATION_4+"<choose><when test=\"item." + entityPropertyNameArray[i] + "!=null\">" + "#{item." + entityPropertyNameArray[i] + "}</when><otherwise>" + columnDefaultValueArray[i] + "</otherwise></choose>" + NEWLINESTR);
				}
				continue;
			}
			if(MysqlUtil.TYPE_NAME_DATETIME.equals(columnTypeArray[i].toLowerCase()) || MysqlUtil.TYPE_NAME_DATE.equals(columnTypeArray[i].toLowerCase())){
				batchInsertObjectSqlSB.append(INDENTATION_4+"<choose><when test=\"item." + entityPropertyNameArray[i] + "!=null\">" + "#{item." + entityPropertyNameArray[i] + ",jdbcType=TIMESTAMP}</when><otherwise>" + columnDefaultValueArray[i] + "</otherwise></choose>," + NEWLINESTR);
			}else{
				batchInsertObjectSqlSB.append(INDENTATION_4+"<choose><when test=\"item." + entityPropertyNameArray[i] + "!=null\">" + "#{item." + entityPropertyNameArray[i] + "}</when><otherwise>" + columnDefaultValueArray[i] + "</otherwise></choose>," + NEWLINESTR);
			}
		}
		batchInsertObjectSqlSB.append(INDENTATION_3 + ")" + NEWLINESTR);
		batchInsertObjectSqlSB.append(INDENTATION_2 + "</foreach>" + NEWLINESTR);
		batchInsertObjectSqlSB.append(INDENTATION_1 + "</insert>" + NEWLINESTR);
		mapperContentSB.append(batchInsertObjectSqlSB.toString());
	}
	/**
	 * 添加 batch update对象 sql语句
	 */
	public static void addBatchUpdateObjectSql(){
		StringBuilder  batchUpdateObjectSqlSB = new StringBuilder();
		batchUpdateObjectSqlSB.append(INDENTATION_1 + "<update id=\"batchUpdate" + ConfigUtil.simpleModelName + "\" parameterType=\"java.util.List\">" + NEWLINESTR);
		batchUpdateObjectSqlSB.append(INDENTATION_2 + "<foreach collection=\"list\" item=\"item\" index=\"index\" open=\"\" close=\"\" separator=\";\">" + NEWLINESTR);
		batchUpdateObjectSqlSB.append(INDENTATION_3 + "update " + ConfigUtil.database_table + " " + ConfigUtil.firstCharLowerSimpleModelName + NEWLINESTR);
		batchUpdateObjectSqlSB.append(INDENTATION_3 + "<set>" + NEWLINESTR);
		for(int i = 1 ; i < columnArray.length ; i ++){
			if(MysqlUtil.TYPE_NAME_DATETIME.equals(columnTypeArray[i].toLowerCase()) || MysqlUtil.TYPE_NAME_DATE.equals(columnTypeArray[i].toLowerCase())){
				batchUpdateObjectSqlSB.append(INDENTATION_4+"<choose><when test=\"item." + entityPropertyNameArray[i] + "!=null\">" + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + " = #{item." + entityPropertyNameArray[i] + ",jdbcType=TIMESTAMP},</when></choose>" + NEWLINESTR);
			}else{
				batchUpdateObjectSqlSB.append(INDENTATION_4+"<choose><when test=\"item." + entityPropertyNameArray[i] + "!=null\">" + ConfigUtil.firstCharLowerSimpleModelName + "." + columnArray[i] + " = #{item." + entityPropertyNameArray[i] + "},</when></choose>" + NEWLINESTR);
			}
		}
		batchUpdateObjectSqlSB.append(INDENTATION_4+ ConfigUtil.firstCharLowerSimpleModelName + "." + primaryKeyColumnName + " = #{item." + primaryKeyInEntityName + "}" + NEWLINESTR);
		batchUpdateObjectSqlSB.append(INDENTATION_3 + "</set>" + NEWLINESTR);
		batchUpdateObjectSqlSB.append(INDENTATION_3 + "where " + ConfigUtil.firstCharLowerSimpleModelName + "." + primaryKeyColumnName + " = #{item." + primaryKeyInEntityName + "}" + NEWLINESTR);
		batchUpdateObjectSqlSB.append(INDENTATION_2 + "</foreach>" + NEWLINESTR);
		batchUpdateObjectSqlSB.append(INDENTATION_1 + "</update>" + NEWLINESTR);
		mapperContentSB.append(batchUpdateObjectSqlSB.toString());
	}
	/**
	 * 添加 batch delete对象 sql语句
	 */
	public static void addBatchDeleteObjectSql(){
		StringBuilder  batchDeleteObjectSqlSB = new StringBuilder();
		batchDeleteObjectSqlSB.append(INDENTATION_1 + "<delete id=\"batchDelete" + ConfigUtil.simpleModelName + "\" parameterType=\"java.util.List\">" + NEWLINESTR);
		batchDeleteObjectSqlSB.append(INDENTATION_2 + "delete "+ ConfigUtil.firstCharLowerSimpleModelName +" from " + ConfigUtil.database_table + " " + ConfigUtil.firstCharLowerSimpleModelName + " where " + ConfigUtil.firstCharLowerSimpleModelName + "." + primaryKeyColumnName  + " in" + NEWLINESTR);
		batchDeleteObjectSqlSB.append(INDENTATION_2 + "<foreach item=\"" + primaryKeyInEntityName + "\" index=\"index\" collection=\"list\" open=\"(\" separator=\",\" close=\")\">#{" + primaryKeyInEntityName + "}</foreach>" + NEWLINESTR);
		batchDeleteObjectSqlSB.append(INDENTATION_1 + "</delete>" + NEWLINESTR);
		mapperContentSB.append(batchDeleteObjectSqlSB.toString());
	}
	/**
	 * 添加 batch delete对象 list sql语句
	 */
	public static void addBatchDeleteObjectListSql(){
		StringBuilder  batchDeleteObjectListSqlSB = new StringBuilder();
		batchDeleteObjectListSqlSB.append(INDENTATION_1 + "<delete id=\"batchDelete" + ConfigUtil.simpleModelName + "List\" parameterType=\"java.util.List\">" + NEWLINESTR);
		batchDeleteObjectListSqlSB.append(INDENTATION_2 + "<foreach collection=\"list\" item=\"item\" index=\"index\" open=\"\" close=\"\" separator=\";\">" + NEWLINESTR);
		batchDeleteObjectListSqlSB.append(INDENTATION_3 + "delete "+ ConfigUtil.firstCharLowerSimpleModelName +" from " + ConfigUtil.database_table + " " + ConfigUtil.firstCharLowerSimpleModelName + " where 1=1 and " + ConfigUtil.firstCharLowerSimpleModelName + "." + primaryKeyColumnName  + " = #{item." + primaryKeyInEntityName + "}" + NEWLINESTR);
		batchDeleteObjectListSqlSB.append(INDENTATION_2 + "</foreach>" + NEWLINESTR);
		batchDeleteObjectListSqlSB.append(INDENTATION_1 + "</delete>" + NEWLINESTR);
		mapperContentSB.append(batchDeleteObjectListSqlSB.toString());
	}
	/**
 	 * 获取列名 在java实体中的名称
 	 * @param columnName
 	 * @return
 	 */
 	private static String getColumnInEntityName(String columnName) {
 		columnName = columnName.toLowerCase();//必须先转换为小写 否则 数据库建表时命名不规范 容易生成的实体属性出现异常
 		String[] tempArray = columnName.split("_");
		StringBuilder sb = new StringBuilder();
		for(String str : tempArray){
			sb.append(str.substring(0, 1).toUpperCase()).append(str.substring(1));
		}
		String str = sb.toString();
		return str.substring(0, 1).toLowerCase() + str.substring(1);
	}
	/**
 	 * 获取表的主键名称
 	 * @param connection 
 	 * @return
 	 * @throws Exception 
 	 */
 	private static String getPrimaryKeyColumnName(DatabaseMetaData dbMeta,String database_name) throws Exception {
 		//获取数据库指定表的主键
		ResultSet primaryKeyResultSet = dbMeta.getPrimaryKeys(database_name,null,ConfigUtil.database_table);
		while(primaryKeyResultSet.next()){
			primaryKeyColumnName = primaryKeyResultSet.getString("COLUMN_NAME");
			System.out.println(ConfigUtil.database_table + "表的主键为：" + primaryKeyColumnName);
			return primaryKeyColumnName;
		}
		if("".equals(primaryKeyColumnName) || primaryKeyColumnName == null ){
			System.out.println(ConfigUtil.database_table + "表必须设置主键，当前没有主键");
			System.exit(0);
		}
		return null;  
	}
	/**
 	 * 添加 namespace 行头内容
 	 * 需要在程序最后添加上mapper结束标签  &lt;/mapper&gt;
 	 */
	public static void addNamespaceRowContent() {
		mapperContentSB.append("<mapper namespace=\"" + ConfigUtil.simpleModelName+"Mapper\">" + NEWLINESTR);
	}
	/**
	 * 将mapper内容 写入mapper文件
	 */
	public static void writeMapperContentToMapperFile(){
		FileWriter fw = null;
		try {
			String filePath = "source/" + ConfigUtil.simpleModelNameLower + "/mapper/" + ConfigUtil.simpleModelName  + "Mapper.xml";
			File mapperFile = new File(filePath);
			if(!mapperFile.exists()){
				mapperFile.createNewFile();
			}
			fw = new FileWriter(mapperFile);
			fw.write(mapperContentSB.toString());
			System.out.println(ConfigUtil.simpleModelName + "Mapper.xml写入成功！文件存放路径为：" + filePath);
		} catch (IOException e) {
			System.out.println(ConfigUtil.simpleModelName + "Mapper.xml写入失败！");
		}finally {
			try {
				fw.close();
			} catch (IOException e) {
				System.out.println("写入mapper文件的写入流关闭是失败！");
			}
		}
	}
	/**
	 * 将entity内容 写入java文件
	 */
	public static void writeEntityContentToEntityFile(){
		FileWriter fw = null;
		try {
			String filePath = "source/" + ConfigUtil.simpleModelNameLower + "/entity/" + ConfigUtil.simpleModelName  + ".java";
			File mapperFile = new File(filePath);
			if(!mapperFile.exists()){
				mapperFile.createNewFile();
			}
			fw = new FileWriter(mapperFile);
			fw.write(entityContentSB.toString());
			System.out.println(ConfigUtil.simpleModelName + ".java写入成功！文件存放路径为：" + filePath);
		} catch (IOException e) {
			System.out.println(ConfigUtil.simpleModelName + ".java写入失败！");
		}finally {
			try {
				fw.close();
			} catch (IOException e) {
				System.out.println("写入java文件的写入流关闭是失败！");
			}
		}
	}
}
